package com.ygxsk.carhome.ui.care;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;

import com.afollestad.materialdialogs.MaterialDialog;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.RegexUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.flyco.roundview.RoundTextView;
import com.jakewharton.rxbinding4.widget.RxTextView;
import com.jakewharton.rxbinding4.widget.TextViewAfterTextChangeEvent;
import com.jakewharton.rxbinding4.widget.TextViewTextChangeEvent;
import com.kongzue.dialogx.dialogs.PopTip;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.alertview.AlertView;
import com.ygxsk.carhome.alertview.OnItemClickListener;
import com.ygxsk.carhome.constant.ConstantApi;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.constant.ExtraValue;
import com.ygxsk.carhome.enumwrap.CardCareTypes;
import com.ygxsk.carhome.enumwrap.CouponUserType;
import com.ygxsk.carhome.enumwrap.IsCarNoType;
import com.ygxsk.carhome.event.EventCardMain;
import com.ygxsk.carhome.event.EventCouponOrPackPush;
import com.ygxsk.carhome.listener.Delivery;
import com.ygxsk.carhome.listener.DoSomeThingListener;
import com.ygxsk.carhome.listener.GainDataCallBackListener;
import com.ygxsk.carhome.listener.RxBus;
import com.ygxsk.carhome.response.CouponCustomer;
import com.ygxsk.carhome.response.CustomerPerson;
import com.ygxsk.carhome.response.EvaluateWadeInfo;
import com.ygxsk.carhome.response.GreatPackageCustomerVo;
import com.ygxsk.carhome.retrofit.AddLogUpLoadInfo;
import com.ygxsk.carhome.retrofit.ApiException;
import com.ygxsk.carhome.retrofit.ApiRequestSubListener;
import com.ygxsk.carhome.retrofit.ApiService;
import com.ygxsk.carhome.retrofit.ErrorConsumer;
import com.ygxsk.carhome.retrofit.NetworkManager;
import com.ygxsk.carhome.retrofit.ResponseTransformer;
import com.ygxsk.carhome.rxbus.RxBusCarWade;
import com.ygxsk.carhome.ui.BaseImmersionFragment;
import com.ygxsk.carhome.ui.evaluate.EvaluateWadePopu;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.views.AmountView;
import com.ygxsk.carhome.views.ClearEditText;
import com.ygxsk.carhome.views.FJEditTextCountPublishTooSmallNoFocus;
import com.ygxsk.integrated.retrofit.Parameterkey;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link CardPushCouponOrPackFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class CardPushCouponOrPackFragment extends BaseImmersionFragment {

    // TODO: Rename parameter arguments, choose names that match
    private static final String ARG_TAB_CLICK_TYPE = "arg_tab_click_type";
    private static final String ARG_TAB_CLICK_NAME = "arg_tab_click_name";

    //该列表的刷新内容
//    @BindView(R.id.refreshlayoutincardsendpushfar)
//    SmartRefreshLayout refreshLayoutInCardSendPush;

    //外侧包裹的滚动布局为了发送完毕清空数据自动滚到底部
    @BindView(R.id.nestedscrollviewincouponpack)
    NestedScrollView nestedScrollViewInCouponPack;

    //卡券类型的默认描述 左侧：卡券类型
    @BindView(R.id.textviewcardtypedespushfra)
    TextView textViewCardTypeDes;

    //卡券的那个类型的文本填充
    @BindView(R.id.textvieweditviewcardtypenamepushfra)
    TextView textViewEditViewCardTypeName;

    //发送数量
//    @BindView(R.id.refreshlayoutincardsendpushfar)
//    TextView textvieweditviewcardtypenamepushfra;


    //发送优惠券的数量
    @BindView(R.id.amount_viewsendcountnumber)
    AmountView amountViewSendCountNumber;

    //优惠券剩余数量的外侧包裹
    @BindView(R.id.linearlayoutsurpluscount)
    LinearLayout linearLayoutSurplusCount;

    //优惠券的剩余数量
    @BindView(R.id.textviewsendsurpluscount)
    TextView textViewSendSurplusCount;

    //客户来源的包裹内容
    @BindView(R.id.radioGroupCheckCareCard)
    RadioGroup radioGroupCheckCareCard;

    //店铺会员
    @BindView(R.id.radiaoButtonChooseTypeStore)
    RadioButton radioButtonChooseTypeStore;

    //平台会员
    @BindView(R.id.radiaoButtonChooseTypePlatform)
    RadioButton radioButtonChooseTypePlatform;

    //填充客户手机号-作为搜索条件
    @BindView(R.id.editviewinputcustomerphonesearchpush)
    ClearEditText editViewInputCustomerPhoneSearch;

    //搜索的文字提示底部贴合的
    @BindView(R.id.textviewcardforbiddenfra)
    TextView textViewCardForbidden;

    //车牌号的选择的逻辑
    @BindView(R.id.linearlayoutcardchoosecoup)
    LinearLayout linearLayoutCardLisenChooseCoup;

    //添加是用来展示车牌号信息的内容
    @BindView(R.id.textvieweditlisnumberpushfra)
    TextView textViewEditLisNumberPushFra;

    //添加发放优惠券的原因文本框
    @BindView(R.id.editviewcontentreasoncoufra)
    FJEditTextCountPublishTooSmallNoFocus editViewContentReasonCou;

    //发送按钮
    @BindView(R.id.layoutbuttoncardplaypushfra)
    RoundTextView layoutButtonCardPlay;

    @BindView(R.id.textviewcouppack)
    TextView textViewCoupPack;


    // TODO: Rename and change types of parameters
    //标志是哪个类型的
    private int tab_click_type;
    private String tab_click_name;

    //卡券类型 列表适配器；是多个动态的展示；
    private ArrayList<CouponCustomer> mDataResources_couponCustomer = new ArrayList<>();
    //礼包的类型 列表适配器 多个动态的展示
    private ArrayList<GreatPackageCustomerVo> mDataResources_greatPackageCustomer = new ArrayList<>();


    //优惠券类型，优惠券礼包类型 优惠券和优惠礼包 目前是通用的一个外侧list数据源
    private ArrayList<EvaluateWadeInfo> mDataResources_cardTypeOrPackageType_popu = new ArrayList<>();

    //外侧 用于遍历 搜索客户人员外侧列表，
    private ArrayList<CustomerPerson> mDataResources_customerPerson_outSide = new ArrayList<>();

    //这里的弹窗是 客户的信息,
    private ArrayList<EvaluateWadeInfo> mDataResources_customerPerson_for_popu = new ArrayList<>();

    //这里是遍历出来车牌号的信息，用来做弹窗展示的
    private ArrayList<EvaluateWadeInfo> mDataResources_customerCarNo_for_popu = new ArrayList<>();

    //选择的这个客户的id ,用在发送 优惠券上；
    private String customerId_upLoad;


    //选中的这个优惠券的id,用在 发送 发放 优惠券上；
    private String couponId_upLoad;
    //选中的礼包类型，做上传用；
    private String couponPackId_upLoad;


    //搜索客户的时候-是否 需要用车牌号搜索；0是不需要车牌号，1是需要车牌号：
    private int isCarNo_upLoad;
    //真实的车牌号信息 上传；
    private String carNo_upLoad;

    /**
     * 当天填写的优惠券的数量默认发放的,默认数量是1
     */
    private int currentNumber = 1;

    //优惠券或者礼包的剩余数量
    private int couponOrPack_surplusCount_outSide;

    //默认是选中类型是【优惠券】,因为顶部选项卡默认选中的是【优惠券】
    private int care_cardOrPackage_type = CardCareTypes.TYPE_COUPONS.getIndex();

    //优惠券类型或者优惠券礼包类型
    private BasePopupView basePopupViewCardTypeOrgreatPackage;
    //弹出是 搜索出来的这个客户的 列表
    private BasePopupView basePopupView_customerPerson;
    //弹窗是车牌的列表逻辑
    private BasePopupView basePopupView_customerNumber;

    //添加
    private MaterialDialog materialDialogCarNumber;


    @OnClick({R.id.layoutcartypepushfra,//选择卡券类型的外侧包裹逻辑
            R.id.layoutbuttoncardplaypushfra,//去派发卡券或者礼包
            R.id.linearlayoutcardchoosecoup//点击车牌号的弹窗打开
    })
    public void ClickInCardFragment(View view) {

        KeyboardUtils.hideSoftInput(CardPushCouponOrPackFragment.this.getActivity());

        switch (view.getId()) {

            case R.id.layoutcartypepushfra: {

                //切换是选中【卡券类型】还是【优惠礼包】类型；
                if (care_cardOrPackage_type == CardCareTypes.TYPE_COUPONS.getIndex()) {

                    //CouponSelectPopu
                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "选中的是优惠券类型");

                    if (mDataResources_cardTypeOrPackageType_popu != null && !mDataResources_cardTypeOrPackageType_popu.isEmpty()) {

                        EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(CardPushCouponOrPackFragment.this.getActivity(),//
                                ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_CARD_TYPE,//
                                mDataResources_cardTypeOrPackageType_popu);

                        evaluateWadePopu.setTitleName(getResources().getString(R.string.please_choose_card_form));

                        //直接弹窗：
                        basePopupViewCardTypeOrgreatPackage = new XPopup.Builder(CardPushCouponOrPackFragment.this.getActivity())
                                .hasShadowBg(true)
                                //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面.
                                .isViewMode(true)
                                //.autoDismiss(false)
                                //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                                //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                                //.dismissOnTouchOutside(true)
                                //.notDismissWhenTouchInView()
                                .moveUpToKeyboard(false)
                                .asCustom(evaluateWadePopu)//
                                .show();

                    } else {

                        //直接获取接口数据
                        getServerDatasCouponType(new GainDataCallBackListener() {
                            @Override
                            public void doSomeThing() {

                                EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(CardPushCouponOrPackFragment.this.getActivity(),//
                                        ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_CARD_TYPE,//
                                        mDataResources_cardTypeOrPackageType_popu);

                                evaluateWadePopu.setTitleName(getResources().getString(R.string.please_choose_card_form));

                                //直接弹窗：
                                basePopupViewCardTypeOrgreatPackage = new XPopup.Builder(CardPushCouponOrPackFragment.this.getActivity())
                                        .hasShadowBg(true)
                                        //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面
                                        .isViewMode(true)
                                        //.autoDismiss(false)
                                        //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                                        //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                                        //.dismissOnTouchOutside(true)
                                        //.notDismissWhenTouchInView()
                                        //.moveUpToKeyboard(false)
                                        .asCustom(evaluateWadePopu)//
                                        .show();

                            }
                        });
                    }


                } else if (care_cardOrPackage_type == CardCareTypes.TYPE_GREAT_PACKAGE.getIndex()) {

                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "选中的是优惠券  礼包 类型");

                    if (mDataResources_cardTypeOrPackageType_popu != null && !mDataResources_cardTypeOrPackageType_popu.isEmpty()) {

                        EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(CardPushCouponOrPackFragment.this.getActivity(),//
                                ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_GREAT_PACKAGE_TYPE,//
                                mDataResources_cardTypeOrPackageType_popu);

                        evaluateWadePopu.setTitleName(getResources().getString(R.string.please_choose_great_package_form));

                        //直接弹窗：
                        basePopupViewCardTypeOrgreatPackage = new XPopup.Builder(CardPushCouponOrPackFragment.this.getActivity())
                                .hasShadowBg(true)
                                //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面.
                                .isViewMode(true)
                                //.autoDismiss(false)
                                //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                                //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                                //.dismissOnTouchOutside(true)
                                //.notDismissWhenTouchInView()
                                .moveUpToKeyboard(false)
                                .asCustom(evaluateWadePopu)//
                                .show();

                    } else {

                        //直接获取礼包的列表接口
                        getServerDatasGreatPackageType(new GainDataCallBackListener() {
                            @Override
                            public void doSomeThing() {

                                EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(CardPushCouponOrPackFragment.this.getActivity(),//
                                        ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_GREAT_PACKAGE_TYPE,//
                                        mDataResources_cardTypeOrPackageType_popu);

                                evaluateWadePopu.setTitleName(getResources().getString(R.string.please_choose_great_package_form));

                                //直接弹窗：
                                basePopupViewCardTypeOrgreatPackage = new XPopup.Builder(CardPushCouponOrPackFragment.this.getActivity())
                                        .hasShadowBg(true)
                                        //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面
                                        .isViewMode(true)
                                        //.autoDismiss(false)
                                        //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                                        //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                                        //.dismissOnTouchOutside(true)
                                        //.notDismissWhenTouchInView()
                                        //.moveUpToKeyboard(false)
                                        .asCustom(evaluateWadePopu)//
                                        .show();

                            }
                        });
                    }

                }

                break;
            }

            case R.id.linearlayoutcardchoosecoup: {//点击 车牌号外侧的包裹

//                new XPopup.Builder(getContext())
//                        .isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
//                        .asCenterList("请选择车牌", new String[]{"条目1", "条目2", "条目3", "条目4"},
//                                null, 1,
//                                new OnSelectListener() {
//                                    @Override
//                                    public void onSelect(int position, String text) {
////                                        toast("click " + text);
//                                    }
//                                })
//                        .show();

                //校验用户的id是不是有，如果用户的手机号是空的，那么
                if (TextUtils.isEmpty(customerId_upLoad)) {//必须填充手机号的
                    CommUtils.checkDialog(mAlertView);
                    mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_phone_search_value), true);
                    mAlertView.show();
                    return;
                }

                method_showCarNumberDialog();

//                View viewCard = View.inflate(mActivityInstance, R.layout.carnumber_dialog, null);
//
//                if (viewCard != null) {
//
//                    //标题内容
//                    TextView tv_namePopu_carNumber = (TextView) viewCard.findViewById(R.id.tv_namepopu_carnumber);
//                    tv_namePopu_carNumber.setText(StringUtils.getString(R.string.dialog_carnumber_title));
//
//                    RecyclerView recyclerViewCarNumbers = (RecyclerView) viewCard.findViewById(R.id.recyclerviewcarnumbers);
//                    recyclerViewCarNumbers.setLayoutManager(new MyLinearLayoutManager(CardPushCouponOrPackFragment.this.getActivity()));
//
//                    CarNumberAdapter carNumberAdapter = new CarNumberAdapter(R.layout.carnumber_adapter, mDataResources_customerCarNo_for_popu);
//                    recyclerViewCarNumbers.setAdapter(carNumberAdapter);
//                    carNumberAdapter.notifyDataSetChanged();
//
//                    carNumberAdapter.setOnItemClickListener(new com.chad.library.adapter.base.listener.OnItemClickListener() {
//                        @Override
//                        public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
//
//                            //
//
//                        }
//                    });
//
//                }
//
//                //激发 弹窗弹出内容
//                materialDialogCarNumber = new MaterialDialog.Builder(CardPushCouponOrPackFragment.this.getActivity())
//                        .customView(viewCard, false)
//                        .contentColor(ColorUtils.getColor(R.color.buttonnomcolor))//
//                        //.positiveText("确定")
//                        //.negativeText("取消")
//                        .positiveColor(ColorUtils.getColor(R.color.dark))
//                        .canceledOnTouchOutside(false)
//                        .show();

                break;
            }

            case R.id.layoutbuttoncardplaypushfra: {//卡券的提交 或者 礼包的提交

                if (care_cardOrPackage_type == CardCareTypes.TYPE_COUPONS.getIndex()) {
                    //如果选中的是优惠券，那么校验优惠券的内容；

                    //校验优惠券的选中
                    if (TextUtils.isEmpty(couponId_upLoad)) {
                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customer_coupon_upload), true);
                        mAlertView.show();
                        return;
                    }

                } else if (care_cardOrPackage_type == CardCareTypes.TYPE_GREAT_PACKAGE.getIndex()) {

                    //如果选中的是 优惠礼包，那么就校验 礼包的选中情况
                    if (TextUtils.isEmpty(couponPackId_upLoad)) {
                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customer_great_package_upload), true);
                        mAlertView.show();
                        return;
                    }

                }

                //校验用户的选中
                if (TextUtils.isEmpty(customerId_upLoad)) {
                    CommUtils.checkDialog(mAlertView);
                    mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customer_person_upload), true);
                    mAlertView.show();
                    return;
                }

                //----------------------------------------------------------------------------------------------
                //如果 是 需要添加车牌的优惠券，限制了需要车牌号，那么
                if (isCarNo_upLoad == IsCarNoType.HAS_NOT_CARNO.getIndex()) {

                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  不用 填充的车牌 弹窗");

                    //而且不需要车牌，那么车牌的信息必然是空
                    carNo_upLoad = "";

                    //如果不需要车牌，即便车牌的包裹布局展示了，那么也要隐藏掉
                    CommUtils.setViewGone(linearLayoutCardLisenChooseCoup);

                } else if (isCarNo_upLoad == IsCarNoType.HAS_CARNO.getIndex()) {
                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  要填充的车牌");

                    if (TextUtils.isEmpty(carNo_upLoad)) {
                        CommUtils.checkDialog(mAlertView);
                        mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.please_choose_lisnum_form), true);
                        mAlertView.show();
                        return;
                    }
                }
                //---------------------------------------------------------------------------------------------------------

                CommUtils.checkDialog(mAlertView);
                mAlertView = new AlertView(StringUtils.getString(R.string.clearaddorsubmitsuretitletips), //提示
                        StringUtils.getString(R.string.alert_message_card_coupon),//提示内容:确定发送吗？
                        StringUtils.getString(R.string.clearcachecancel), //取消
                        new String[]{StringUtils.getString(R.string.clearaddorsubmitsure)},//确定
                        null, mActivityInstance, AlertView.Style.Alert, new OnItemClickListener() {//
                    @Override
                    public void onItemClick(Object o, int position) {

                        if (position != AlertView.CANCELPOSITION) {

                            if (care_cardOrPackage_type == CardCareTypes.TYPE_COUPONS.getIndex()) {

                                //如果选中的是优惠券，那么发放优惠券
                                method_gainAddSubmitInfo_upLoad_for_couponCard();

                            } else if (care_cardOrPackage_type == CardCareTypes.TYPE_GREAT_PACKAGE.getIndex()) {
                                //如果选中的是礼包，那么发放优惠券
                                method_gainAddSubmitInfo_upLoad_for_greatPackage();

                            }

                        }
                    }
                });

                mAlertView.setCancelable(true);
                mAlertView.show();

                //跳转到发放页面的布局；
//                Bundle extra_bundle = new Bundle();
//                    //String shopId = assetInSideBean.getShopId();
//                    //是添加进来的
//                    extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE,ExtraValue.VALUE_JUMP_FORM_ASSET_ADD);
//                    extra_bundle.putString(ExtraKey.EXTRA_ASSETINSIDEBEAN_SHOPID,assetInSideBean.getShopId());
//                    //携带服务站的列表过去
//                    extra_bundle.putParcelableArrayList(ExtraKey.EXTRA_ASSETSTATIONINFOLISTFORADDASSET, assetStationInfoListForAddAsset);
//                    //携带资产的归属方
//                    extra_bundle.putParcelableArrayList(ExtraKey.EXTRA_ASSETUNDERBUSINESSINFOLISTOUTSIDE, assetUnderBusinessInfoListOutSide);
//
                //这个也是车辆的分配 信息:
                // : 2023-07-15 08:43 携带不同的标志;
//                ActivityUtils.startActivity(extra_bundle, CustomerPersonActivity.class);


                break;
            }

            default:
                break;
        }

    }


    public CardPushCouponOrPackFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @return A new instance of fragment CardPushCouponOrPackFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static CardPushCouponOrPackFragment newInstance(int _tab_click_type, String _tab_click_name) {

        CardPushCouponOrPackFragment fragment = new CardPushCouponOrPackFragment();

        Bundle args = new Bundle();

        args.putInt(ARG_TAB_CLICK_TYPE, _tab_click_type);
        args.putString(ARG_TAB_CLICK_NAME, _tab_click_name);

        fragment.setArguments(args);

        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "tab_click_name-->" + _tab_click_name);

        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mFragmentInstance = this;
        mActivityInstance = this.getActivity();

        if (getArguments() != null) {

            tab_click_type = getArguments().getInt(ARG_TAB_CLICK_TYPE);
            tab_click_name = getArguments().getString(ARG_TAB_CLICK_NAME);

            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "tab_click_name-->" + tab_click_name);

        }

        if (mDataResources_couponCustomer == null) {
            mDataResources_couponCustomer = new ArrayList<>();
        }

        if (mDataResources_greatPackageCustomer == null) {
            mDataResources_greatPackageCustomer = new ArrayList<>();
        }

        if (mDataResources_customerPerson_outSide == null) {
            mDataResources_customerPerson_outSide = new ArrayList<>();
        }

        //因为发送消息清空卡券和礼包内容。
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }


    }


    //默认选中【优惠券】有一些条件的重置，
    private void method_refresh_reset_type_coupons_or_pack_all() {

        //清空上传的重要数据

        //清空优惠券的上传的id
        couponId_upLoad = "";

        //清空礼包的优惠礼包id上传
        couponPackId_upLoad = "";

        //剩余发送数量 重置为0
        couponOrPack_surplusCount_outSide = 0;

        //设置客户来源
        if (radioButtonChooseTypeStore != null) {
            radioButtonChooseTypeStore.setChecked(true);
        }

        if (radioButtonChooseTypePlatform != null) {
            radioButtonChooseTypePlatform.setChecked(false);
        }

        //清空车牌号信息
        isCarNo_upLoad = 0;

        //清空车牌号信息
        carNo_upLoad = "";

        Delivery.getInstance().post(new Runnable() {
            @Override
            public void run() {

                if (tab_click_type == CardCareTypes.TYPE_COUPONS.getIndex()) {

                    //默认文字：类型是 请选择优惠券
                    if (textViewCardTypeDes != null) {
                        textViewCardTypeDes.setText(getString(R.string.choose_card_coupon_two));
                    }

                    //默认 选中 卡券的或者是礼包 填充的类型
                    if (textViewEditViewCardTypeName != null) {
                        textViewEditViewCardTypeName.setText("");
                        textViewEditViewCardTypeName.setHint(getString(R.string.please_choose_card_form));
                    }

//                    //如果是优惠券，要隐藏剩余数量
//                    CommUtils.setViewInvisible(linearLayoutSurplusCount);

                    getServerDatasCouponType(null);

                } else if (tab_click_type == CardCareTypes.TYPE_GREAT_PACKAGE.getIndex()) {

                    //显示礼包类型
                    if (textViewCardTypeDes != null) {
                        textViewCardTypeDes.setText(getString(R.string.choose_card_type_package));
                    }

                    //默认是礼包类型，调用礼包类型的接口
                    if (textViewEditViewCardTypeName != null) {
                        textViewEditViewCardTypeName.setText("");
                        textViewEditViewCardTypeName.setHint(getString(R.string.please_choose_great_package_form));
                    }

//                    CommUtils.setViewInvisible(linearLayoutSurplusCount);

                    getServerDatasGreatPackageType(null);

                }

                //剩余发送数量 重置为0
//                couponOrPack_surplusCount_outSide = 0;

                //隐藏剩余发送数量
                CommUtils.setViewInvisible(linearLayoutSurplusCount);

                //客户的来源的重置
                //店铺会员 重置为选中
                if (radioButtonChooseTypeStore != null) {
                    radioButtonChooseTypeStore.setChecked(true);
                }

                //平台会员 重置为不选中
                if (radioButtonChooseTypePlatform != null) {
                    radioButtonChooseTypePlatform.setChecked(false);
                }

                // 清空手机号信息
                if (editViewInputCustomerPhoneSearch != null) {
                    editViewInputCustomerPhoneSearch.setText("");
                }

                //手机号底部的那个选中小信息
                if (textViewCardForbidden != null) {
                    textViewCardForbidden.setText("");
                    textViewCardForbidden.setVisibility(View.GONE);
                }

                //车牌号重置为空的
                if (textViewEditLisNumberPushFra != null) {
                    textViewEditLisNumberPushFra.setText("");
                }

                //发送原因重置为空
                if (editViewContentReasonCou != null) {
                    editViewContentReasonCou.setText("");
                }

            }
        });

        //布局列表自动滚动到顶部
        if (nestedScrollViewInCouponPack != null) {
            nestedScrollViewInCouponPack.post(new Runnable() {
                @Override
                public void run() {

//                  nestedScrollViewInCouponPack.smoothScrollBy(0,0);
                    nestedScrollViewInCouponPack.fullScroll(NestedScrollView.FOCUS_UP);

                    //发送数量重置
                    if (amountViewSendCountNumber.getEtAmount() != null) {

                        boolean isEditable = amountViewSendCountNumber.getEtAmount().isFocusable();

                        if (isEditable) {

                            amountViewSendCountNumber.getEtAmount().setText(String.valueOf(ConstantSign.AMOUNT_COUNT_ONE));
                            amountViewSendCountNumber.getEtAmount().setFocusable(false);
                            amountViewSendCountNumber.getEtAmount().setFocusableInTouchMode(true);

                        } else {
                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--------------------------数字输入框是不可编辑的--------------------");
                        }

                    }

                }
            });

        }

    }

    @Override
    protected void initView() {
        super.initView();

        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--initView--initView");

        CommUtils.methodHelpView4(textViewCoupPack);

        //---------------------------------------------------------------------------------------------
        //选中用户的弹窗列表，选择优惠券的卡券类型。
        mCompositeDisposable.add(RxBus.getInstance()
                .toObserverable(RxBusCarWade.class)//
                .subscribeOn(AndroidSchedulers.mainThread())//
                .observeOn(AndroidSchedulers.mainThread())//
                .subscribe(new Consumer<RxBusCarWade>() {

                    @Override
                    public void accept(RxBusCarWade rxBusCarWade) throws Throwable {

                        if (rxBusCarWade != null) {

                            if (rxBusCarWade.getActionFlag() == ExtraValue.MODIFY_EVALUATE_CARMAIN_PERSON_SELECT) {//【选择卡券发放的那个人】；

                                //搜索出这个被发放人员的
                                customerId_upLoad = rxBusCarWade.getEvaluateWadeInfo().getDictCode();
//                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--customerId_upLoad-->" + customerId_upLoad);

                                //车牌的弹窗清空
                                if (mDataResources_customerCarNo_for_popu != null && !mDataResources_customerCarNo_for_popu.isEmpty()) {
                                    mDataResources_customerCarNo_for_popu.clear();
                                }

                                //2023-9-18 11:31:57 遍历选出来的
                                if (mDataResources_customerPerson_outSide != null && !mDataResources_customerPerson_outSide.isEmpty()) {

                                    for (CustomerPerson customerPerson : mDataResources_customerPerson_outSide) {

                                        if (TextUtils.equals(customerId_upLoad, String.valueOf(customerPerson.getCustomerId()))) {

//                                            carNo_upLoad = customerPerson.getCarNo();
//                                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--carNo_upLoad-->" + carNo_upLoad);

                                            ArrayList<String> carNoList = customerPerson.getCarNoList();

                                            if (carNoList != null && !carNoList.isEmpty()) {

                                                for (String itemValue : carNoList) {

                                                    EvaluateWadeInfo evaluateCardNumber = new EvaluateWadeInfo();
                                                    //这是区分勾选唯一的标志
                                                    evaluateCardNumber.setDictCode(itemValue);
                                                    evaluateCardNumber.setDictLabel(itemValue);
                                                    evaluateCardNumber.setCarNumber(itemValue);

                                                    if (mDataResources_customerCarNo_for_popu != null) {
                                                        mDataResources_customerCarNo_for_popu.add(evaluateCardNumber);
                                                    }

                                                }

                                            }

                                        }
                                    }

                                }

                                CommUtils.setTextTips_success(CardPushCouponOrPackFragment.this.getActivity(), textViewCardForbidden, rxBusCarWade.getEvaluateWadeInfo().getDictLabel());

                                //修改文本
//                                if (textViewInputPhoneChoose != null) {
//                                    textViewInputPhoneChoose.setText(rxBusCarWade.getEvaluateWadeInfo().getDictLabel());
//                                }

                                //----------------------------------------------------------------------------------------------------------------
                                //如果真的需要车牌 那么再计算车牌的填充，如果不需要车牌，那么就一直隐藏

                                //这里需要判断
                                if (isCarNo_upLoad == IsCarNoType.HAS_NOT_CARNO.getIndex()) {

                                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  不用 填充的车牌 弹窗");

                                    CommUtils.setViewGone(linearLayoutCardLisenChooseCoup);


                                } else if (isCarNo_upLoad == IsCarNoType.HAS_CARNO.getIndex()) {

                                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  要填充的车牌");

                                    CommUtils.setViewVisible(linearLayoutCardLisenChooseCoup);

                                    //填充车牌的内容
                                    try {

                                        if (mDataResources_customerCarNo_for_popu != null && !mDataResources_customerCarNo_for_popu.isEmpty()) {

                                            CommUtils.setViewVisible(linearLayoutCardLisenChooseCoup);

                                            //如果数据仅仅只有一条，那么直接填充这个车牌信息
                                            if (mDataResources_customerCarNo_for_popu.size() == 1) {

                                                carNo_upLoad = mDataResources_customerCarNo_for_popu.get(0).getDictLabel();

                                                mDataResources_customerCarNo_for_popu.get(0).setChecked(true);
                                                String carNumber = mDataResources_customerCarNo_for_popu.get(0).getDictLabel();

                                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "这里携带的唯一个车牌信息是->" + carNumber);

                                                CommUtils.setText(textViewEditLisNumberPushFra, carNumber);

                                            } else {

                                                //其他情况下 不设置任何操作.
                                                CommUtils.setText(textViewEditLisNumberPushFra, "");

                                                LogUtils.json(ConstantSign.LOGCAT_NOMAL + "多车牌信息是->", mDataResources_customerCarNo_for_popu);
                                                //    [
                                                //      "冀A99997",
                                                //      "豫Q12345",
                                                //      "豫Q12346",
                                                //      "冀Q12345"
                                                //    ]

                                            }

                                        } else {
                                            //没有车牌 是否提示下没有车牌信息？
                                        }

                                    } catch (Exception e) {
                                        //catch
                                        e.printStackTrace();
                                    }


                                }
                                //----------------------------------------------------------------------------------------------------------------

                            } else if (rxBusCarWade.getActionFlag() == ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_CARD_TYPE) {//【选择卡券类型】；是优惠券的 选中 点出

                                couponId_upLoad = rxBusCarWade.getEvaluateWadeInfo().getDictCode();
//                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--couponId_upLoad-->" + couponId_upLoad);

                                //2023-9-18 遍历 isCarNo 字段信息
                                if (mDataResources_couponCustomer != null && !mDataResources_couponCustomer.isEmpty()) {

                                    for (CouponCustomer couponCustomerItem : mDataResources_couponCustomer) {

                                        if (TextUtils.equals(couponId_upLoad, couponCustomerItem.getCouponId())) {

                                            isCarNo_upLoad = couponCustomerItem.getIsCarNo();

                                            //取出优惠券的剩余数量：
                                            couponOrPack_surplusCount_outSide = couponCustomerItem.getSurplusCount();

                                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "-选择卡券的类型是否需要车牌-isCarNo_upLoad-->" + isCarNo_upLoad);
                                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "-选中的卡券的剩余数量-couponOrPack_surplusCount_outSide-->" + couponOrPack_surplusCount_outSide);

                                        }

                                    }

                                }

                                //-----------------------------------------------------------------------------------------------
                                //填充选中的优惠券的 那个类型
                                if (textViewEditViewCardTypeName != null) {
                                    textViewEditViewCardTypeName.setText(rxBusCarWade.getEvaluateWadeInfo().getDictLabel());
                                }
                                //-----------------------------------------------------------------------------------------------
                                //如果是卡券发送，要展示逻辑，如果是优惠礼包 那么要隐藏剩余数量。
                                if (tab_click_type == CardCareTypes.TYPE_COUPONS.getIndex()) {

                                    //数字输入框 设置最大库存数量
                                    if (amountViewSendCountNumber != null) {
                                        amountViewSendCountNumber.setGoods_storage(couponOrPack_surplusCount_outSide);
                                    }

                                    //填充优惠券的 剩余数量
                                    if (textViewSendSurplusCount != null) {
                                        textViewSendSurplusCount.setText(String.valueOf(couponOrPack_surplusCount_outSide));
                                    }

                                    //卡券的剩余数量，的显示或者隐藏
                                    CommUtils.setViewVisible(linearLayoutSurplusCount);

                                } else if (tab_click_type == CardCareTypes.TYPE_GREAT_PACKAGE.getIndex()) {

                                    //数字输入框的 设置最大库存量
                                    if (amountViewSendCountNumber != null) {
                                        amountViewSendCountNumber.setGoods_storage(ConstantApi.AMOUNT_NUMBER_INITIAL_MIN);
                                    }

                                    //设置礼包的剩余数量 始终是1
                                    if (textViewSendSurplusCount != null) {
                                        textViewSendSurplusCount.setText(String.valueOf(ConstantApi.AMOUNT_NUMBER_INITIAL_MIN));
                                    }

                                    //卡券的剩余数量的显示或者隐藏.
                                    CommUtils.setViewVisible(linearLayoutSurplusCount);

                                }

                                //----------------------------------------------------------------------------------------------------
                                method_couponAndpack_clearData_by_selectCardType();

                                //---------------------------------------------------------------------------------------------------------


                            } else if (rxBusCarWade.getActionFlag() == ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_GREAT_PACKAGE_TYPE) {//【选择大礼包类型】

                                couponPackId_upLoad = rxBusCarWade.getEvaluateWadeInfo().getDictCode();
//                              LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--couponId_upLoad-->" + couponId_upLoad);

                                //2023-9-18 遍历 isCarNo 字段信息
                                if (mDataResources_greatPackageCustomer != null && !mDataResources_greatPackageCustomer.isEmpty()) {

                                    for (GreatPackageCustomerVo greatPackageCustomerVoItem : mDataResources_greatPackageCustomer) {

                                        if (TextUtils.equals(couponPackId_upLoad, greatPackageCustomerVoItem.getCouponPackId())) {

                                            isCarNo_upLoad = greatPackageCustomerVoItem.getIsCarNo();
                                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--大礼包的类型选中--isCarNo_upLoad-->" + isCarNo_upLoad);

                                        }

                                    }
                                }

                                if (textViewEditViewCardTypeName != null) {
                                    textViewEditViewCardTypeName.setText(rxBusCarWade.getEvaluateWadeInfo().getDictLabel());
                                }

                                //2024-3-6 16:10:24如果选中的优惠券 需要车牌的，只能是【店铺会员】可以勾选，平台会员不能勾选；
                                method_couponAndpack_clearData_by_selectCardType();

                            } else if (rxBusCarWade.getActionFlag() == ExtraValue.MODIFY_EVALUATE_CARMAIN_CARNUMBER_SELECT) {

                                //选中的车牌信息
                                carNo_upLoad = rxBusCarWade.getEvaluateWadeInfo().getDictLabel();

                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "选中的车牌信息是->" + carNo_upLoad);
                                CommUtils.setText(textViewEditLisNumberPushFra, rxBusCarWade.getEvaluateWadeInfo().getDictLabel());

                            }
                        }
                    }
                }));


        // TODO: 2024/3/3 16:28 要告知触发切换 ？

        if (tab_click_type == CardCareTypes.TYPE_COUPONS.getIndex()) {

            care_cardOrPackage_type = CardCareTypes.TYPE_COUPONS.getIndex();

            amountViewSendCountNumber.setGoods_storage(ConstantApi.AMOUNT_NUMBER_INITIAL_MAX);
            amountViewSendCountNumber.getEtAmount().setEnabled(true);
            amountViewSendCountNumber.getEtAmount().setFocusable(true);

            // TODO: 2023-10-07 15:29 如果类型值被填充，清空上次选中的【优惠券类型】
            couponId_upLoad = "";

            //默认文字：类型是 请选择优惠券
            if (textViewCardTypeDes != null) {
                textViewCardTypeDes.setText(getResources().getString(R.string.choose_card_coupon_two));
            }

            if (textViewEditViewCardTypeName != null) {
                textViewEditViewCardTypeName.setText("");
                textViewEditViewCardTypeName.setHint(getString(R.string.please_choose_card_form));
            }

            //调用优惠券类型的接口:仅仅是优惠券的
            getServerDatasCouponType(null);


        } else if (tab_click_type == CardCareTypes.TYPE_GREAT_PACKAGE.getIndex()) {

            care_cardOrPackage_type = CardCareTypes.TYPE_GREAT_PACKAGE.getIndex();

            //优惠礼包只能限制1个数据
            amountViewSendCountNumber.setGoods_storage(ConstantApi.AMOUNT_NUMBER_INITIAL_MIN);
            amountViewSendCountNumber.getEtAmount().setEnabled(false);
            amountViewSendCountNumber.getEtAmount().setFocusable(false);

            //重置礼包的类型
            couponPackId_upLoad = "";

            //显示礼包类型
            if (textViewCardTypeDes != null) {
                textViewCardTypeDes.setText(getString(R.string.choose_card_type_package));
            }

            //默认是礼包类型，调用礼包类型的接口
            if (textViewEditViewCardTypeName != null) {
                textViewEditViewCardTypeName.setText("");
                textViewEditViewCardTypeName.setHint(getString(R.string.please_choose_great_package_form));
            }

            // TODO: 2023-10-07 15:29 如果类型值被填充，要清空处理
            //如果卡券类型或者礼包类型 有值，还是要清空的；
            getServerDatasGreatPackageType(null);

        }


        //  数量限制   因为你 加减号的内容 是不能超过   你订阅的总数量的
        if (amountViewSendCountNumber != null) {

            amountViewSendCountNumber.setOnAmountChangeListener(new AmountView.OnAmountChangeListener() {

                @Override
                public void onAmountChange(View view, int amount) {

                    //CommUtils.displayToastShortCenter(String.valueOf(amount));

                    if (amount >= 1) {

                        currentNumber = amount;

                    } else {

                        ToastUtils.showShort(getResources().getString(R.string.input_enable_num));
                    }

                    //LogUtils.d("itchen---添加的数字 是 " + amount);

                }
            });

        }

        //-------------------------------------------
        //对于数字的监听
        RxTextView.textChangeEvents(amountViewSendCountNumber.getEtAmount())//
                .debounce(ConstantApi.TIME_DELAY400, TimeUnit.MILLISECONDS)//可以不要延迟
                .subscribeOn(AndroidSchedulers.mainThread())
                .observeOn(AndroidSchedulers.mainThread())//
                .subscribe(new Consumer<TextViewTextChangeEvent>() {
                    @Override
                    public void accept(TextViewTextChangeEvent textViewTextChangeEvent) throws Throwable {

                        if (textViewTextChangeEvent != null) {

                            if (!TextUtils.isEmpty(textViewTextChangeEvent.getText().toString().trim())) {

                                if ((textViewTextChangeEvent.getText().toString().trim()).startsWith(ConstantSign.NUMBER_ZERO)) {

                                    //LogUtils.d("itchen--->第一次取到："+textViewTextChangeEvent.getText().toString().trim());

                                    amountViewSendCountNumber.getEtAmount().setText(ConstantSign.AMOUNT_COUNT_ONE + (textViewTextChangeEvent.getText().toString().trim()).substring(1));

                                }

                            }

                        }
                    }
                });

        //-------------------------------------------
        //客户来源的切换逻辑
        if (radioGroupCheckCareCard != null) {
            radioGroupCheckCareCard.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {

                    //"userType": 0 //搜索会员类型：0：店铺会员；1：平台会员
                    if (checkedId == R.id.radiaoButtonChooseTypeStore) {

                        //店铺会员
//                        String currentPhone = editViewInputCustomerPhoneSearch.getText().toString().trim();
//
//                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "店铺会员的 勾中状态->" + radiaoButtonChooseTypeStore.isChecked());
//
//                        if (!TextUtils.isEmpty(currentPhone)) {
//                            //重新触发 根据手机号搜索客户的接口
//                            gainCustomerByPhone(currentPhone, false);
//                        }

                        //清空客户id
                        customerId_upLoad = "";
                        //清空手机号信息
                        CommUtils.setText(editViewInputCustomerPhoneSearch, "");

                    } else if (checkedId == R.id.radiaoButtonChooseTypePlatform) {

                        //平台会员
//                        String currentPhone = editViewInputCustomerPhoneSearch.getText().toString().trim();
//
//                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "平台会员的 勾中状态->" + radiaoButtonChooseTypePlatform.isChecked());
//
//                        if (!TextUtils.isEmpty(currentPhone)) {
//
//                            //重新触发 根据手机号搜索客户的接口
//                            gainCustomerByPhone(currentPhone, false);
//
//                        }


                        //清空客户id
                        customerId_upLoad = "";
                        //清空手机号信息
                        CommUtils.setText(editViewInputCustomerPhoneSearch, "");

                        //需要判断是否需要车牌
                        if (isCarNo_upLoad == IsCarNoType.HAS_NOT_CARNO.getIndex()) {

                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  不用 填充的车牌 弹窗");


                        } else if (isCarNo_upLoad == IsCarNoType.HAS_CARNO.getIndex()) {

                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  要填充的车牌");

                            //重置选中状态
                            if (radioButtonChooseTypeStore != null) {
                                radioButtonChooseTypeStore.setChecked(true);
                            }

                            if (radioButtonChooseTypePlatform != null) {
                                radioButtonChooseTypePlatform.setChecked(false);
                            }

                            //您选择的卡券类型只支持店铺会员
                            CommUtils.checkDialog(mAlertView);
                            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_coupon_type_support), true);
                            mAlertView.show();

                        }

                    }

                }
            });
        }
        //-------------------------------------------

        //软键盘的【搜索】
        if (editViewInputCustomerPhoneSearch != null) {
            editViewInputCustomerPhoneSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {

                    if (actionId == EditorInfo.IME_ACTION_SEARCH || (keyEvent != null && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {

                        //关闭软键盘
                        KeyboardUtils.hideSoftInput(CardPushCouponOrPackFragment.this.getActivity());

                        method_SearchSomeThing(false);

                        return true;
                    }

                    return false;
                }
            });
        }

        //监听手机号的文本框：如果手机号文本框输入信息丢失，那么 textViewInputPhoneChoose 的文字 也改为原始文字：
        RxTextView.afterTextChangeEvents(editViewInputCustomerPhoneSearch)
//                .debounce(ConstantApi.TIME_DELAY100, TimeUnit.MILLISECONDS)//立即执行搜索
                .debounce(0, TimeUnit.MILLISECONDS)//立即执行搜索,
                .skip(1)//过滤到第一个空字符的内容,需要完整的手机号
                .subscribeOn(AndroidSchedulers.mainThread())//
                .observeOn(AndroidSchedulers.mainThread())//
                .subscribe(new Consumer<TextViewAfterTextChangeEvent>() {
                    @Override
                    public void accept(TextViewAfterTextChangeEvent textViewAfterTextChangeEvent) throws Throwable {

                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "过滤之后-监听到的内容是->" + textViewAfterTextChangeEvent.getView().getText().toString());

                        String inputValue = textViewAfterTextChangeEvent.getView().getText().toString();

                        if (!TextUtils.isEmpty(inputValue)) {

                            int length = inputValue.length();

                            if (length < ConstantApi.IS_PHONE_NUMBER_LENGTH) {

                                //如果小于11位，那么控制搜索按钮不可用？,那就说明还没有结果，要隐藏提示语句
                                CommUtils.setViewGone(textViewCardForbidden);

                            } else if (length == ConstantApi.IS_PHONE_NUMBER_LENGTH) {

//                                determinate_circular_small_progress.setVisibility(View.VISIBLE);

                                //触发搜索立即关闭软键盘
                                KeyboardUtils.hideSoftInput(CardPushCouponOrPackFragment.this.getActivity());

                                method_SearchSomeThing(false);

                            }

//                            else {
//                                determinate_circular_small_progress.setVisibility(View.GONE);
//                            }

                        } else {
                            //如果是直接清空的，那么也要隐藏底部小提示。
                            CommUtils.setViewGone(textViewCardForbidden);
                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "文字手机号搜索的 文本执行了清空操作");

                            customerId_upLoad = "";
                            //车牌号也清空
                            carNo_upLoad = "";
                            CommUtils.setText(textViewEditLisNumberPushFra, "");

                        }

//                        if (et_searchInCustom.isFocused()) {
//                                //LogUtils.d(ConstantApi.LOGCAT_NOMAL + "afterTextChangeEvents--处于获取焦点状态");
//                                et_searchInCustom.clearFocus();//如果处于占用焦点之中，那么清理焦点
//                            }

//                        if (TextUtils.isEmpty(textViewAfterTextChangeEvent.getView().getText().toString())) {
//                            if (textViewInputPhoneChoose != null) {
//                                textViewInputPhoneChoose.setText(getString(R.string.smartgo_des_search_full));
//                            }
//                        }

                    }
                }, new Consumer<Throwable>() {

                    @Override
                    public void accept(Throwable throwable) throws Throwable {
                        //
                    }
                });


//        if (refreshLayoutInCardSendPush != null) {
//
//            refreshLayoutInCardSendPush.setOnRefreshListener(new OnRefreshListener() {
//                @Override
//                public void onRefresh(@NonNull RefreshLayout refreshLayout) {
//
//                    refreshLayout.getLayout().post(new Runnable() {
//                        @Override
//                        public void run() {
//
////                            gainDatas();
//                            //这里应该是仅仅刷新优惠券的列表
//                            getServerDatasCouponType(null);
//
//                            refreshLayout.finishRefresh();
//
//                        }
//                    });
//
//                }
//            });
//
//        }

    }

    //因为 切换顶部的优惠券或者优惠礼包，导致的底部内容变动，优惠券和优惠礼包通用的方法
    private void method_couponAndpack_clearData_by_selectCardType() {

        //如果是需要车牌号的用户，那么只能搜索【店铺会员】不能搜索【平台会员】
        if (isCarNo_upLoad == IsCarNoType.HAS_NOT_CARNO.getIndex()) {

            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  不用 填充的车牌 弹窗");

            CommUtils.setViewGone(linearLayoutCardLisenChooseCoup);


        } else if (isCarNo_upLoad == IsCarNoType.HAS_CARNO.getIndex()) {

            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  要填充的车牌");

            CommUtils.setViewVisible(linearLayoutCardLisenChooseCoup);

            //如果此刻此时已经选中了【平台会员】，那么需要切换到勾中【店铺会员】,如果此时选中的是店铺会员，那么不用动逻辑。
            if (radioButtonChooseTypePlatform != null) {

                if (radioButtonChooseTypePlatform.isChecked()) {

                    if (radioButtonChooseTypeStore != null) {
                        radioButtonChooseTypeStore.setChecked(true);
                    }

                    if (radioButtonChooseTypePlatform != null) {
                        radioButtonChooseTypePlatform.setChecked(false);
                    }

                    //并且给出一句话提示
                    ToastUtils.showShort(mActivityInstance.getResources().getString(R.string.check_coupon_type_support));

                }
            }

        }
        //---------------------------------------------------------------------------------------------------------

        //客户的手机号信息清空
        if (editViewInputCustomerPhoneSearch != null) {
            editViewInputCustomerPhoneSearch.setText("");
        }

        //如果搜索出来有用户，那么清空用户id
        customerId_upLoad = "";

        //如果搜索出来有车牌，那么清空车牌
        carNo_upLoad = "";

        //清空车牌的已填充的车牌号信息
        if (textViewEditLisNumberPushFra != null) {
            textViewEditLisNumberPushFra.setText("");
        }

    }

//    private void method_handler_radioButton() {
////        如果 "isCarNo": 1,   必定要查店铺会员  ， 如果 "isCarNo": 0  才会判断 "userType": 0 查询用户类型
//         //您选择的卡券类型只支持店铺会员
//        //这里需要判断
//        if (isCarNo_upLoad == IsCarNoType.HAS_NOT_CARNO.getIndex()) {
//
//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  不用 填充的车牌 弹窗");
//
//
//
//
//
//        } else if (isCarNo_upLoad == IsCarNoType.HAS_CARNO.getIndex()) {
//
//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  要填充的车牌");
//
//            //立即选中为【店铺会员】，并且禁用【平台会员】
//            if (radiaoButtonChooseTypeStore!=null){
//                radiaoButtonChooseTypeStore.setChecked(true);
//            }
//
//            if (radiaoButtonChooseTypePlatform!=null){
//                radiaoButtonChooseTypePlatform.setChecked(false);
//            }
//
//
//
//        }
//
//    }

    @Override
    protected void initData() {
        super.initData();

        gainDatas();

    }

    @Override
    protected void gainDatas() {

        //默认是要取出优惠券的类型接口
        //是否有其他需要调用接口的地方；
        if (NetworkUtils.isConnected()) {

            //同时间获取卡券类型的列表
//            getServerDatasCouponType(null);

            //这个次要，如果没有直接不展示也可以，但是卡券类型必须先获取为了提交数据；
//          getServerDatasCardHistory();

        } else {

            //是否有其他的执行逻辑？
            //netWorkError();
            // : 2023-08-14 15:22 添加页面遮盖，使用adapter自有的方式来填充

        }


    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_card_push_coupon_or_pack;
    }

    @Override
    public void onClickNodata(View view) {

        //retain

    }


    //通用的搜索逻辑,以手机号为搜索条件
    private void method_SearchSomeThing(boolean isShowLoadDialog) {

        String inputPhoneNumber = editViewInputCustomerPhoneSearch.getText().toString().trim();

        //手机号没有填写，是不能通过的
        if (TextUtils.isEmpty(inputPhoneNumber)) {//必须填充手机号的
            CommUtils.checkDialog(mAlertView);
            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customerphone_upload), true);
            mAlertView.show();
            return;
        }

        //校验用户输入的手机号
        if (!RegexUtils.isMobileSimple(inputPhoneNumber)) {
            //CommUtils.displayToastShort(LoginActivity.this, "电话格式不对");
            CommUtils.checkDialog(mAlertView);
            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customerphone_format), true);
            mAlertView.show();
            return;
        }

        if (!RegexUtils.isMobileExact(inputPhoneNumber)) {//精确验证手机号
            //CommUtils.displayToastShort(LoginActivity.this, "请输入有效手机号");
            CommUtils.checkDialog(mAlertView);
            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, getString(R.string.check_customerphone_effective), true);
            mAlertView.show();
            return;
        }

        if (mDataResources_customerPerson_for_popu != null && !mDataResources_customerPerson_for_popu.isEmpty()) {
            mDataResources_customerPerson_for_popu.clear();
        }


        method_gainCustomerByPhone(editViewInputCustomerPhoneSearch.getText().toString().trim(), isShowLoadDialog);


    }

    //搜索客户的信息内容 :根据手机号搜索客户信息
    private void method_gainCustomerByPhone(String _userPhone, boolean isShowLoadDialog) {

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.phone, _userPhone);//,
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());
        //map.put(Parameterkey.isCarNo, CouponIsCarNoType.ISCARNUMBER_NO.getIndex());//是否限制车牌使用：0代表否；1代表 是；限制车牌查询店铺会员，不限制查询平台会员；
        //是否限制车牌使用:0否；1是  （优惠券或者礼包读取）
        map.put(Parameterkey.isCarNo, isCarNo_upLoad);//是否限制车牌使用：0代表否；1代表 是；限制车牌查询店铺会员，不限制查询平台会员；

//         enum CouponUserType {
//            //搜索会员类型：0：店铺会员；1：平台会员
//            IS_STORE(0, "店铺会员"),
//            IS_PLATFORM(1, "平台会员");

        //默认勾中 店铺会员.

        if (radioButtonChooseTypeStore != null && radioButtonChooseTypeStore.isChecked()) {

            map.put(Parameterkey.userType, CouponUserType.IS_STORE.getIndex());//是店铺会员

        } else if (radioButtonChooseTypePlatform != null && radioButtonChooseTypePlatform.isChecked()) {

            map.put(Parameterkey.userType, CouponUserType.IS_PLATFORM.getIndex());//是平台会员

        } else {

            //默认设置【店铺会员】
            map.put(Parameterkey.userType, CouponUserType.IS_STORE.getIndex());//是店铺会员

        }

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETTYPECUSTOMERBYPHONE_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getTypeCustomerByPhone_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(false);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getTypeCustomerByPhone(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
//                .compose(CardPushCouponOrPackFragment.this.getActivity().b(FragmentEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<ArrayList<CustomerPerson>>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        CommUtils.checkMaterialDialog(materialDialog);
                        CommUtils.setViewVisible(textViewCardForbidden);
                        CommUtils.myCustomMessageShow(mActivityInstance, textViewCardForbidden, serverMessage);

                        //未能搜索出客户，那么车牌信息也是必然隐藏的
                        CommUtils.setViewGone(linearLayoutCardLisenChooseCoup);

                        //无数据的需要转换提示
                        //{"data":"","message":"无数据","code":"20002"}

                        //勿删除：
                        //这里仅仅给提示即可
//                        if (!TextUtils.isEmpty(serverMessage)) {
////                            ToastUtils.showShort(serverMessage);
//                            PopTip.show(serverMessage).iconWarning();
//                        } else {
//                            PopTip.show(getString(R.string.not_search_customer)).iconWarning();
//                        }

                    }
                }))
                .doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                        CommUtils.setViewGone(textViewCardForbidden);

                        if (isShowLoadDialog) {
                            //如果是自动搜索的，就不弹加载进度圈
                            //如果是点击【搜索】，就弹窗
                            method_create_materialDialog(ConstantSign.TIPS_LOADING);

                        }

                    }
                }).subscribe(new Consumer<ArrayList<CustomerPerson>>() {
                    @Override
                    public void accept(ArrayList<CustomerPerson> customerPersonArrayList) throws Throwable {

                        //如果搜索出来有数据，就隐藏软键盘
                        KeyboardUtils.hideSoftInput(mActivityInstance);

                        CommUtils.setViewGone(textViewCardForbidden);

                        //搜索完毕，即关闭进度圈
                        CommUtils.checkMaterialDialog(materialDialog);

                        if (mDataResources_customerPerson_for_popu != null && !mDataResources_customerPerson_for_popu.isEmpty()) {
                            mDataResources_customerPerson_for_popu.clear();
                        }

                        if (mDataResources_customerPerson_outSide != null && !mDataResources_customerPerson_outSide.isEmpty()) {
                            mDataResources_customerPerson_outSide.clear();
                        }

                        if (customerPersonArrayList != null && !customerPersonArrayList.isEmpty()) {

                            for (CustomerPerson customerPerson : customerPersonArrayList) {

                                EvaluateWadeInfo evaluateWadeInfo = new EvaluateWadeInfo();
                                //
                                evaluateWadeInfo.setDictCode(customerPerson.getCustomerId());
                                evaluateWadeInfo.setDictLabel(customerPerson.getTrueName());
                                //这个特殊，需要展示手机号信息
                                evaluateWadeInfo.setUserPhoneNumber(customerPerson.getPhone());
                                //这个也是特殊展示，展示车牌号的:2024-3-4 13:44:16已经废弃了这种单个车牌的做法，最终改成了是车牌的list:
                                evaluateWadeInfo.setCarNumber(customerPerson.getCarNo());
                                //填充车牌的列表
                                evaluateWadeInfo.setCarNoList(customerPerson.getCarNoList());

                                //默认都是false
                                evaluateWadeInfo.setChecked(false);

                                if (mDataResources_customerPerson_for_popu != null) {
                                    mDataResources_customerPerson_for_popu.add(evaluateWadeInfo);
                                }

                                if (mDataResources_customerPerson_outSide != null) {
                                    mDataResources_customerPerson_outSide.add(customerPerson);
                                }

                            }

                            //-----------------------------------------------------------------------------------------------------------
                            //如果数据仅仅是只有一条，那么默认直接选中，减少一步用户操作：
                            if (mDataResources_customerPerson_for_popu != null && mDataResources_customerPerson_for_popu.size() == 1) {
                                mDataResources_customerPerson_for_popu.get(0).setChecked(true);
                            }
                            //-----------------------------------------------------------------------------------------------------------


                        } else {
                            //直接提示 搜索信息为空
                            PopTip.show(getString(R.string.not_search_customer)).iconWarning();
                        }

                        //-----------------------------------------------------------------------------------------------------------
                        //-----------------------------------------------------------------------------------------------------------
                        if (mDataResources_customerPerson_for_popu != null && !mDataResources_customerPerson_for_popu.isEmpty()) {

//                             enum IsCarNoType {
//                                //0是不需要车牌号，1是需要车牌号：
//                                HAS_NOT_CARNO(0, "不需要车牌号"),
//                                HAS_CARNO(1, "需要车牌号");

                            //这里需要判断
                            if (isCarNo_upLoad == IsCarNoType.HAS_NOT_CARNO.getIndex()) {

                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  不用 填充的车牌 弹窗");

                                method_showCustomerPersonDialog();

                                CommUtils.setViewGone(linearLayoutCardLisenChooseCoup);


                            } else if (isCarNo_upLoad == IsCarNoType.HAS_CARNO.getIndex()) {

                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  要填充的车牌");

                                method_showCustomerPersonDialog();

                            }

                        } else {
                            //如果搜索的客户信息是空，那么车牌如何处理？
                        }
                        //-----------------------------------------------------------------------------------------------------------

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {

                        //页面报错；
                        CommUtils.checkMaterialDialog(materialDialog);
                        CommUtils.setViewGone(textViewCardForbidden);

                    }
                });

    }

    //添加：弹出搜索出来的客户的列表，一般地是仅仅只有一条数据的；
    private void method_showCustomerPersonDialog() {

        EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(CardPushCouponOrPackFragment.this.getActivity(),//
                ExtraValue.MODIFY_EVALUATE_CARMAIN_PERSON_SELECT,//
                mDataResources_customerPerson_for_popu);

        evaluateWadePopu.setTitleName(getResources().getString(R.string.dialog_des_title));

        //搜索要弹窗的：客户信息
        basePopupView_customerPerson = new XPopup.Builder(CardPushCouponOrPackFragment.this.getActivity())
                .hasShadowBg(true)
                //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面;
                .isViewMode(true)
                //.autoDismiss(false)
                //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                //.dismissOnTouchOutside(true)
                //.notDismissWhenTouchInView()
                .asCustom(evaluateWadePopu)//
                .show();

    }

    //展示车辆车牌的弹窗
    private void method_showCarNumberDialog() {

        EvaluateWadePopu evaluateWadePopu = new EvaluateWadePopu(CardPushCouponOrPackFragment.this.getActivity(),//
                ExtraValue.MODIFY_EVALUATE_CARMAIN_CARNUMBER_SELECT,//
                mDataResources_customerCarNo_for_popu);

        evaluateWadePopu.setTitleName(getResources().getString(R.string.dialog_carnumber_title));

        //搜索要弹窗的：客户信息
        basePopupView_customerNumber = new XPopup.Builder(CardPushCouponOrPackFragment.this.getActivity())
                .hasShadowBg(true)
                //.moveUpToKeyboard(false) //如果不加这个，评论弹窗会移动到软键盘上面;
                .isViewMode(true)
                //.autoDismiss(false)
                //.isDestroyOnDismiss(true) //对于只使用一次的弹窗，推荐设置这个
                //.isThreeDrag(false) //是否开启三阶拖拽，如果设置enableDrag(false)则无效
                //.dismissOnTouchOutside(true)
                //.notDismissWhenTouchInView()
                .asCustom(evaluateWadePopu)//
                .show();

    }


    //获取优惠券的类型；页面打开默认直接调取的；
    private void getServerDatasCouponType(GainDataCallBackListener _gainDataCallBackListener) {

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());//,
//        map.put(Parameterkey.pagination, pagination_upLoad);//传递的页码
//        map.put(Parameterkey.pageSize, Parameterkey.pageSize_default);//,搜索关键字

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETCOUPONBYSHOPINFO_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getCouponByShopInfo_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getCouponByShopInfo(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
//                .compose(CardMainPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<ArrayList<CouponCustomer>>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);
                        //
                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                        //2024-1-3 10:51:00 bug:刷新优惠券弹窗列表的同时要清空
                        if (mDataResources_couponCustomer != null && !mDataResources_couponCustomer.isEmpty()) {
                            mDataResources_couponCustomer.clear();
                        }

                        if (mDataResources_cardTypeOrPackageType_popu != null && !mDataResources_cardTypeOrPackageType_popu.isEmpty()) {
                            mDataResources_cardTypeOrPackageType_popu.clear();
                        }

                    }
                }).subscribe(new Consumer<ArrayList<CouponCustomer>>() {
                    @Override
                    public void accept(ArrayList<CouponCustomer> couponCustomers) throws Throwable {

                        if (couponCustomers != null && !couponCustomers.isEmpty()) {

                            for (CouponCustomer couponCustomerItem : couponCustomers) {

                                EvaluateWadeInfo evaluateWadeInfo = new EvaluateWadeInfo();
                                evaluateWadeInfo.setDictCode(couponCustomerItem.getCouponId());//优惠券的id
                                evaluateWadeInfo.setDictLabel(couponCustomerItem.getCouponName());//优惠券的名称

                                if (mDataResources_cardTypeOrPackageType_popu != null) {
                                    mDataResources_cardTypeOrPackageType_popu.add(evaluateWadeInfo);
                                }

                                if (mDataResources_couponCustomer != null) {
                                    mDataResources_couponCustomer.add(couponCustomerItem);
                                }

                            }

                        }

                        //额外的执行
                        if (_gainDataCallBackListener != null) {
                            _gainDataCallBackListener.doSomeThing();
                        }

                    }
                }, new ErrorConsumer() {
                    @Override
                    protected void error(ApiException apiException) {
                        //页面报错；
                        function_apiException(apiException);
                    }
                });
    }

    //获取 礼包的类型；可以直接获取，也可以当选中【优惠礼包】时候再次获取
    private void getServerDatasGreatPackageType(GainDataCallBackListener _gainDataCallBackListener) {

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());//,
//        map.put(Parameterkey.pagination, pagination_upLoad);//传递的页码
//        map.put(Parameterkey.pageSize, Parameterkey.pageSize_default);//,搜索关键字

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_GETCOUPONPACKLISTBYSHOP_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.getCouponPackListByShop_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(false);//展示给用户的标志
        addLogUpLoadInfo.setAlertToUser(true);
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .getCouponPackListByShop(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
//                .compose(CardMainPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<ArrayList<GreatPackageCustomerVo>>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        //没有优惠礼包给醒目提示
                        function_response_20002(serverCode, serverMessage, addLogUpLoadInfo, false);

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "优惠礼包执行到 是否清空数据操作");

                        if (mDataResources_greatPackageCustomer != null && !mDataResources_greatPackageCustomer.isEmpty()) {
                            mDataResources_greatPackageCustomer.clear();
                        }

                        if (mDataResources_cardTypeOrPackageType_popu != null && !mDataResources_cardTypeOrPackageType_popu.isEmpty()) {
                            mDataResources_cardTypeOrPackageType_popu.clear();
                        }

                    }
                }).subscribe(new Consumer<ArrayList<GreatPackageCustomerVo>>() {
                    @Override
                    public void accept(ArrayList<GreatPackageCustomerVo> greatPackageCustomers) throws Throwable {

                        //无数据的时候 是否走到执行成功逻辑。
//                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "执行到 是否清空数据操作");

                        if (greatPackageCustomers != null && !greatPackageCustomers.isEmpty()) {

                            for (GreatPackageCustomerVo greatPackageCustomerVoItem : greatPackageCustomers) {

                                // TODO: 2023-10-07 15:50 纠错
                                EvaluateWadeInfo evaluateWadeInfo = new EvaluateWadeInfo();
                                evaluateWadeInfo.setDictCode(greatPackageCustomerVoItem.getCouponPackId());//优惠券的id
                                evaluateWadeInfo.setDictLabel(greatPackageCustomerVoItem.getCouponName());//优惠券的名称

                                if (mDataResources_cardTypeOrPackageType_popu != null) {
                                    mDataResources_cardTypeOrPackageType_popu.add(evaluateWadeInfo);
                                }

                                //选中 做上传 是 优惠礼包类型的；
                                if (mDataResources_greatPackageCustomer != null) {
                                    mDataResources_greatPackageCustomer.add(greatPackageCustomerVoItem);
                                }

                            }

                        }

                        //额外的执行
                        if (_gainDataCallBackListener != null) {
                            _gainDataCallBackListener.doSomeThing();
                        }

                    }
                }, new ErrorConsumer() {
                    @Override
                    protected void error(ApiException apiException) {
                        //页面报错；
                        function_apiException(apiException);
                    }
                });
    }

    //执行上传发送这个优惠券的操作,发放卡券的接口
    private void method_gainAddSubmitInfo_upLoad_for_couponCard() {

        //发送优惠券的原因
        String explainText = editViewContentReasonCou.getText().toString().trim();

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.customerId, customerId_upLoad);//用户ID
        map.put(Parameterkey.couponId, couponId_upLoad);//优惠券主键Id
        map.put(Parameterkey.carNo, carNo_upLoad);//车牌
        map.put(Parameterkey.explain, explainText);//发送优惠券原因
        map.put(Parameterkey.everyCount, currentNumber);//发送优惠券的数量值

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_SENDCOUPONTOCUSTOMER_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.sendCouponToCustomer_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setAlertToUser(true);
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .sendCouponToCustomer(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
//                .compose(CardMainPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<String>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        CommUtils.checkMaterialDialog(materialDialog);

                        function_response_20002(serverCode, serverMessage, addLogUpLoadInfo, false);

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {
                        method_create_materialDialog(ConstantSign.TIPS_SUBMIT);
                    }
                }).subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String stringValue) throws Throwable {

                        CommUtils.checkMaterialDialog(materialDialog);

                        //这里提交成功之后，删除文本框之中的手机号信息
//                        if (editViewInputCustomerPhoneSearch != null) {
//
////                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "editViewInputCustomerPhoneSearch-重置为空");
//                            editViewInputCustomerPhoneSearch.post(new Runnable() {
//                                @Override
//                                public void run() {
//
//                                    editViewInputCustomerPhoneSearch.setText("");
////                                    if (textViewInputPhoneChoose != null) {
////                                        textViewInputPhoneChoose.setText(getString(R.string.smartgo_des_search_full));
////                                    }
//
//                                }
//                            });
//
//                        }

                        //TipDialog.show(StringUtils.getString(R.string.add_submit_success), WaitDialog.TYPE.SUCCESS);


                        //: 2024/1/10 16:57 发送礼包完毕，通知首页的发放历史记录刷新。
                        EventCardMain eventCardMain = new EventCardMain();
                        eventCardMain.setMessage(ExtraValue.EVENTBUS_EVENT_TO_REFRESH_CARD_MAIN_LIST);
                        EventBus.getDefault().post(eventCardMain);

                        methodSubmitSuccessTwoSecond(CardPushCouponOrPackFragment.this.getActivity(), new DoSomeThingListener() {
                            @Override
                            public void doSomeThing() {

                                //重新刷新 历史记录列表，因为有新数据 新增了；
//                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "即将执行 刷新 发放的历史记录 接口");
//                                methodBack();

                                // TODO: 2024/3/4 10:28 发送完毕 界面 还关闭吗？
                                method_refresh_reset_type_coupons_or_pack_all();

                            }
                        });

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {

                        function_apiException(apiException);

                    }
                });

    }

    //发送礼包的接口
    private void method_gainAddSubmitInfo_upLoad_for_greatPackage() {

        String explainText = editViewContentReasonCou.getText().toString().trim();

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.customerId, customerId_upLoad);//
        map.put(Parameterkey.couponPackId, couponPackId_upLoad);//此礼包的 id
        map.put(Parameterkey.carNo, carNo_upLoad);//
        map.put(Parameterkey.explain, explainText);//发送优惠券礼包的原因
        //发送礼包 的数量 不用携带 everyCount；

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_SENDCOUPONTOCUSTOMER_GREAT_PACKAGE_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.sendCouponToCustomer_great_package_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setAlertToUser(true);
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .sendCouponToCustomer_great_package(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
//                .compose(CardMainPushActivity.this.bindUntilEvent(ActivityEvent.DESTROY))
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<String>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        CommUtils.checkMaterialDialog(materialDialog);

                        function_response_20002(serverCode, serverMessage, addLogUpLoadInfo, false);

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                        method_create_materialDialog(ConstantSign.TIPS_SUBMIT);

                    }
                }).subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String stringValue) throws Throwable {

                        CommUtils.checkMaterialDialog(materialDialog);

                        //这里提交成功之后，删除文本框之中的手机号信息
//                        if (editViewInputCustomerPhoneSearch != null) {
//
////                            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "editViewInputCustomerPhoneSearch-重置为空");
//                            editViewInputCustomerPhoneSearch.post(new Runnable() {
//                                @Override
//                                public void run() {
//
//                                    editViewInputCustomerPhoneSearch.setText("");
//
////                                    if (textViewInputPhoneChoose != null) {
////                                        textViewInputPhoneChoose.setText(getString(R.string.smartgo_des_search_full));
////                                    }
//
//                                }
//                            });
//
//                        }

                        //TipDialog.show(StringUtils.getString(R.string.add_submit_success), WaitDialog.TYPE.SUCCESS);


                        //: 2024/1/10 16:57 发送礼包完毕，通知首页的发放历史记录刷新。
                        EventCardMain eventCardMain = new EventCardMain();
                        eventCardMain.setMessage(ExtraValue.EVENTBUS_EVENT_TO_REFRESH_CARD_MAIN_LIST);
                        EventBus.getDefault().post(eventCardMain);

                        methodSubmitSuccessTwoSecond(CardPushCouponOrPackFragment.this.getActivity(), new DoSomeThingListener() {
                            @Override
                            public void doSomeThing() {

                                //重新刷新 历史记录列表，因为有新数据 新增了；
//                                LogUtils.d(ConstantSign.LOGCAT_NOMAL + "即将执行 刷新 发放的历史记录 接口");

                                // TODO: 2024/3/4 10:29 发送完毕还通知页面关闭吗？
//                                methodBack();
                                method_refresh_reset_type_coupons_or_pack_all();

                            }
                        });

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {
                        //
//                        if (apiException != null) {
//                            if (!TextUtils.isEmpty(apiException.getDisplayMessage())) {
//                                ToastUtils.showShort(apiException.getDisplayMessage());
//                            }
//                        }

                        function_apiException(apiException);

                    }
                });

    }

//    //限制车牌的展示或者隐藏
//    private void method_handler_cardListenAndRadio(int _isCarNo_choose) {
//
//        //-----------------------------------------------------------------
//        //如果是需要车牌号的用户，那么只能搜索【店铺会员】不能搜索【平台会员】
//        if (_isCarNo_choose == IsCarNoType.HAS_NOT_CARNO.getIndex()) {
//
//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  不用 填充的车牌 弹窗");
//
//            CommUtils.setViewGone(linearLayoutCardLisenChooseCoup);
//
//
//        } else if (_isCarNo_choose == IsCarNoType.HAS_CARNO.getIndex()) {
//
//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "打开  要填充的车牌");
//
//            CommUtils.setViewVisible(linearLayoutCardLisenChooseCoup);
//
//            //如果此刻此时已经选中了【平台会员】，那么需要切换到勾中【店铺会员】,如果此时选中的是店铺会员，那么不用动逻辑。
//            if (radioButtonChooseTypePlatform != null) {
//
//                if (radioButtonChooseTypePlatform.isChecked()) {
//
//                    if (radioButtonChooseTypeStore != null) {
//                        radioButtonChooseTypeStore.setChecked(true);
//                    }
//
//                    if (radioButtonChooseTypePlatform != null) {
//                        radioButtonChooseTypePlatform.setChecked(false);
//                    }
//
//                    //并且给出一句话提示
//                    ToastUtils.showShort(mActivityInstance.getResources().getString(R.string.check_coupon_type_support));
//
//                }
//            }
//
//        }
//        //-----------------------------------------------------------------
//
//    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThreadEventCouponOrPack(EventCouponOrPackPush eventCouponOrPackPush) {

        if (eventCouponOrPackPush != null) {

            if (eventCouponOrPackPush.getMessage() == ExtraValue.EVENTBUS_EVENT_TO_CLEAR_CARD_COUPON_OR_PACK_PUSH) {

                if (mFragmentInstance != null) {
                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "收到了清空历史数据-->" + mFragmentInstance.getClass().getSimpleName().toString().hashCode());

                    if (mFragmentInstance.isAdded()) {

                        method_refresh_reset_type_coupons_or_pack_all();

                    }
                }

            }

        }

    }

    @Override
    public void onDestroy() {
        super.onDestroy();

        if (mDataResources_customerCarNo_for_popu != null) {
            mDataResources_customerCarNo_for_popu.clear();
            mDataResources_customerCarNo_for_popu = null;
        }

        CommUtils.checkMaterialDialog(materialDialogCarNumber);

        EventBus.getDefault().unregister(this);

    }
}